package cn.wsalix.weixin.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import cn.anlaser.entity.SimpleEntity;
import cn.wsalix.admin.entity.SysUser;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "WX_USER")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Data
@EqualsAndHashCode(callSuper = false)
@ToString(exclude = { "user"})
public class WxUser extends SimpleEntity {
	private String subscribe;
	private String openid;
	private String nickname;
	private String sex;
	private String language;
	private String city;
	private String province;
	private String country;
	private String headimgurl;
	private String subscribe_time;
	private String unionid;
	private String remark;
	private String groupid;
	private String privilege;

	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_WXUSER_USER"), name = "USER_ID")
	private SysUser user;

	@OneToOne(optional = true, cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
	@PrimaryKeyJoinColumn(name = "ID", referencedColumnName = "ID")
	private WxAccessToken wxAccessToken;
	
	private String errcode="0";
	private String errmsg;

}
